var qcloud = require("../vendor/wafer2-client-sdk/index")
var config = require("../config")
var util = require ("../utils/util")

function login(successHandler)
{
  var locker = util.showBusy("正在登录");
  qcloud.login({
    success: res =>
    {
      util.showSuccess(locker, "登录成功");
      var app = getApp();
      app.globalData.isLogin = true;
      app.globalData.userInfo = res.userinfo;
      app.globalData.userInfo.userId = res.userId;
      app.globalData.credit = res.credit;
      app.globalData.address = res.address;
      app.globalData.enableEncashment = res.enableEncashment;
      successHandler(res);
    },
    fail: err =>
    {
      util.showModel("登录失败", err.message);
    }
  });
}

module.exports = 
{
  login,
}